/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Utils;


import java.io.*;
import java.net.*;

/**
 *
 * @author alejo
 */
public class VPSocketStream {

   //Point coordinates
   private int x = 0;
   private int y = 0;

   private int fidelity = 0;

   //msg number
   private int msgNum = 0;

   Socket socket;
   DataInputStream in;

   public VPSocketStream (String ipAddr, int port)
   {
       try
       {
           
           socket = new Socket (ipAddr, port);
           socket.setSoLinger (true, 10);
       }
       catch(Exception e)
       {}
   }

   public String toString ()
   {
       String result;
       result = Integer.toString(x) + " " + Integer.toString(y);
       return result;
   }

   public int getX()
   {
       return x;
   }

   public int getY()
   {
       return y;
   }

   public int getMsgNum()
   {
       return msgNum;
   }

   public int getFidelity()
   {
       return fidelity;
   }

    public void readObject() throws IOException
    {

       this.in =  new DataInputStream(socket.getInputStream());

       if(in.available()>=3)
       {
            msgNum = in.readInt();
            x = in.readInt();
            y = in.readInt();
            fidelity = in.readInt();
       }
    }

    public void close()
    {
        try
        {
            socket.close();
        }
        catch(Exception e)
        {}
    }

    public void finalize()
    {
        close();
    }

}


